package com.gitee.zycra.future.job.common.config;

import com.gitee.zycra.future.job.common.serializer.LocalDateDeserializer;
import com.gitee.zycra.future.job.common.serializer.LocalDateSerializer;
import com.gitee.zycra.future.job.common.serializer.LocalDateTimeDeserializer;
import com.gitee.zycra.future.job.common.serializer.LocalDateTimeSerializer;
import com.gitee.zycra.future.job.common.serializer.LocalTimeDeserializer;
import com.gitee.zycra.future.job.common.serializer.LocalTimeSerializer;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * @author zycra
 */
@Component
public class DateTimeSerializerConfig {

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return builder -> builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer())
                .serializerByType(LocalDate.class, new LocalDateSerializer())
                .serializerByType(LocalTime.class, new LocalTimeSerializer())
                .deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer())
                .deserializerByType(LocalDate.class, new LocalDateDeserializer())
                .deserializerByType(LocalTime.class, new LocalTimeDeserializer());
    }
}
